<?php
/* Message Test cases generated on: 2010-11-16 11:11:30 : 1289902890*/
App::import('Model', 'Message');

class MessageTestCase extends CakeTestCase {
	var $fixtures = array('app.message', 'app.user', 'app.group', 'app.contractor_profile', 'app.designer_profile', 'app.comment', 'app.design', 'app.pitch', 'app.pitch_subscription', 'app.design_photo', 'app.job');

	function startTest() {
		$this->Message =& ClassRegistry::init('Message');
		$_SESSION['Auth']['User']['id'] = 1;
		$_SESSION['Auth']['User']['username'] = 'userone';
	}

	function endTest() {
		unset($this->Message);
		ClassRegistry::flush();
		unset($_SESSION['Auth']['User']);
	}
	
	function testGetInbox() {
		$this->assertEqual(count($this->Message->get_inbox('userone')), 2);

		$this->assertEqual(count($this->Message->get_inbox('userthree')), 3);
		
		$this->assertFalse($this->Message->get_inbox());
	}
	
	function testGetOutbox() {
		$result = $this->Message->get_outgoing(1);
		$result = count($result);
		$expected = 3;
		$this->assertEqual($result, $expected);
		
		$result = $this->Message->get_outgoing();
		$this->assertFalse($result);
	}
	
	function testGetConversation() {
		$this->assertFalse($this->Message->get_conversation());
		$this->assertEqual(count($this->Message->get_conversation(1)), 3);
		$this->assertEqual(count($this->Message->get_conversation(2)), 3);
	}
	
	function testSend() {
		$this->assertFalse($this->Message->send());
		
		$testData = array(
			'Message' => array(
				'parent_id' => 0,
				'to' => 'usertwo',
				'subject' => 'subject',
				'body' => 'Lorem ipsum enzovoorts',
			)
		);
		$this->assertTrue($this->Message->send($testData));
		
		$testData = array(
			'Message' => array(
				'parent_id' => 1,
				'to' => 'userthree',
				'subject' => 'RE: subject',
				'body' => 'Lorem ipsum once again',
			)
		);
		$this->assertTrue($this->Message->send($testData));
		
		$testData = array(
			'Message' => array(
				'parent_id' => 1,
				'to' => 'usersix',
				'subject' => 'RE: subject',
				'body' => 'Lorem ipsum once again',
			)
		);
		$this->assertFalse($this->Message->send($testData));
		
		unset($_SESSION['Auth']['User']);
		$this->assertFalse($this->Message->send($testData));
	
	}
	
	function testDeleteConversation() {
		$this->assertFalse($this->Message->delete_conversation());
		
		$_SESSION['Auth']['User']['id'] = 1;
		$_SESSION['Auth']['User']['username'] = 'userone';
		$this->assertTrue($this->Message->delete_conversation(1));
		
		$this->assertTrue($this->Message->delete_conversation(5));
	}
	
	function testGetReplyData() {
		$expected = array(
			'Message' => array(
				'parent_id' => 1,
				'to' => 'userone',
				'subject' => 'RE: Lorem ipsum dolor sit amet'
			)
		);
		$this->assertEqual($this->Message->get_reply_data(1), $expected);
		
		$expected = array(
			'Message' => array(
				'parent_id' => 1,
				'to' => 'userthree',
				'subject' => 'RE: Lorem ipsum dolor sit amet'
			)
		);
		$this->assertEqual($this->Message->get_reply_data(2), $expected);
		
		$this->assertFalse($this->Message->get_reply_data());
	}
	
	function testMarkAsRead() {
		$this->assertFalse($this->Message->mark_as_read());
		
		$testData = array(
			'Message' => array(
				'id' => 7,
				'parent_id' => 4,
				'user_id' => 1,
				'to_user' => 2,
				'read' => 0,
			)
		);
		$this->assertTrue($this->Message->mark_as_read($testData));
	}
	
	function testRemoveRe() {
		$this->assertFalse($this->Message->remove_re());
		
		$this->assertEqual($this->Message->remove_re('This is a subject'), 'This is a subject');
		
		$this->assertEqual($this->Message->remove_re('RE: This is a subject'), 'This is a subject');
	}

}
?>
